package com.geostar.constructionland.analyse.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.geostar.constructionland.analyse.entity.alyresult.AlyResultDzzhyfq;
import com.geostar.constructionland.analyse.service.adjust.AdjustService;
import com.geostar.constructionland.analyse.service.analyseresult.AlyResultDzzhyfqService;
import com.geostar.constructionland.common.entity.aly.AdjustResponse;
import com.geostar.constructionland.common.entity.response.LandInfo;
import com.geostar.constructionland.common.entity.response.model.AdjustModel;
import feign.Body;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @author yelll
 * @since 2020-5-25 17:04
 * 平差分析
 **/
@Api("平差算法接口")
@RestController
@Slf4j
public class AdjustController {

    @Autowired
    AlyResultDzzhyfqService dzzhyfqService;

    @Autowired
    AdjustService adjustService;

    @ApiOperation(value = "平差算法",notes = "对占压分析数据进行占压面积平差")
    @PostMapping(value = "/adjust")
    @ResponseBody
    public AdjustResponse adjustLandArea(@RequestBody AdjustModel adjustModel) throws Exception{
        AdjustResponse adjustResponse;
        log.info("平差接口获取数据："+new ObjectMapper().writeValueAsString(adjustModel));
        try {
            List<LandInfo> adjustedList = adjustService.adjust(adjustModel);
            adjustResponse = AdjustResponse.createBySuccess(adjustedList);
        }catch (Exception e){
            e.printStackTrace();
            adjustResponse = AdjustResponse.createByErrorMessage(e.getMessage());
        }
        return adjustResponse;
    }

}
